﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TMScore_Subsets
{
    public partial class MainForm : Form //main form
    {
        public MainForm()
        {
            InitializeComponent();
        }


        /// <summary>
        /// Initializes all program
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            Dictionary<string, string> m_AllDocs1 = new Dictionary<string, string>();
            button1.Enabled = false;
            Tuple<int, int, bool, bool, Dictionary<string, Tuple<string, List<string>, DateTime, double>>, int, int> allDoc = ReadFile.ReadAllFile();
            foreach (string name in allDoc.Item5.Keys)
            {
                m_AllDocs1[name] = allDoc.Item5[name].Item1;

            }
            Dictionary<string, string> m_AllDocs = Parser.MainFunction(allDoc.Item3, m_AllDocs1); //parser
            DocumentsManager manager = new DocumentsManager();
            manager.CreateAllDocuments(allDoc, m_AllDocs); // craete the doduments objects
            System.IO.StreamWriter file;
            // create a writer and open the file

            using (file = new System.IO.StreamWriter(@"info.txt",false)) // print to file all the doc fields
            {
                foreach (Document d in manager.allDocuments)
                {


                    file.WriteLine(d.m_Name + "," + d.time + "," + d.TMScore); //line 1- doc name,mail time,the tmscore
                    foreach (string name in d.receivers) //line 2- tme mail receivers
                    {
                        file.Write(name + ",");
                    }
                    file.WriteLine(" ");
                    foreach (KeyValuePair<int, int> pair in d.Fingerprints)// line 3- fingerprints- dic <int,int>
                    {
                        file.Write(pair.Key + "," + pair.Value + ",");
                    }
                    file.WriteLine(" ");

                }
            }
            file.Close();

        }
    }
}

       
     

